//if submit button is clicked
$('#subdcribeButton').click(function () {		
	
	//Get the data from all the fields
	var email = $('input[name=subscriber-email]');
	var name = $('input[name=subscriber-name]');
	var storename = $('input[name=subscriber-store]');
	var storeid = $('input[name=subscriber-store-id]');

	//Simple validation to make sure user entered something
	//If error found, add hightlight class to the text field
	if (email.val()=='' || email.val()=='Enter Email') {
		document.getElementById('subscriber-email').style.border='3px solid red';
		$('#subscriber-email').focus();
		return false;
	}
	//organize the data properly
	var data = 'email=' + email.val()+'&name='+name.val()+'&storename='+storename.val()+'&storeid='+storeid.val();
	
	//disabled all the text fields
	//$('#sMail').attr('disabled','true');

	var filter = /^((([a-z]|[A-Z]|[0-9]|\-|_)+(\.([a-z]|[A-Z]|[0-9]|\-|_)+)*)@((((([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.))*([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
	if (!filter.test(email.val())){
		document.getElementById('subscriber-email').style.border='3px solid red';
		$('#subscriber-email').focus();
		return false;
	}

	//start the ajax
	$.ajax({
		//this is the php file that processes the data and send mail
		url: "/subscribeEmail",	
		
		//GET method is used
		type: "GET",

		//pass the data			
		data: data,		
		
		//Do not cache the page
		cache: false,
		
		//success
		success: function (html) {		
			//if process.php returned 1/true (send mail success)
			if (html=='') {					
				//hide the form
				$('#subscriberForm').fadeOut('slow');					
				
				//show the success message
				$('#done').fadeIn('slow');
				
				//set cookie
				var b=1000*60*60*24*7;var a=new Date((new Date()).valueOf()+b);document.cookie="footerSubscribe=true;expires="+a.toUTCString()
				
			//if process.php returned 0/false (send mail failed)
			} else alert('Sorry, unexpected error. Please try again later.');				
		}		
	});
	
	//cancel the submit button default behaviours
	return false;
});	

//if submit button is clicked
$('#subscriberFinish').click(function () {		
	
	//Get the data from all the fields
	var email = $('input[name=subscriberemail]');
	var name = $('input[name=subscribername]');
	var storename = $('input[name=subscriber-store]');
	var storeid = $('input[name=subscriber-store-id]');

	//Simple validation to make sure user entered something
	//If error found, add hightlight class to the text field
	if (email.val()=='') {
		document.getElementById('subscriberemail').style.border='3px solid red';
		$('#subscriberemail').focus();
		return false;
	}
	//organize the data properly
	var data = 'email=' + email.val()+'&name='+name.val()+'&storename='+storename.val()+'&storeid='+storeid.val();
	
	//disabled all the text fields
	//$('#sMail').attr('disabled','true');

	var filter = /^((([a-z]|[A-Z]|[0-9]|\-|_)+(\.([a-z]|[A-Z]|[0-9]|\-|_)+)*)@((((([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.))*([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
	if (!filter.test(email.val())){
		document.getElementById('subscriberemail').style.border='3px solid red';
		$('#subscriberemail').focus();
		return false;
	}
	$('#subscriberFinish').fadeOut('fast');
	//start the ajax
	$.ajax({
		//this is the php file that processes the data and send mail
		url: "/subscribeEmail",	
		
		//GET method is used
		type: "GET",

		//pass the data			
		data: data,		
		
		//Do not cache the page
		cache: false,
		
		//success
		success: function (html) {		
			//if process.php returned 1/true (send mail success)
			if (html=='') {					
				$('#subscriberemail').val('');
				$('#subscribername').val('');
				
				//show the success message
				$('#finish').fadeIn('slow');
				
			//if process.php returned 0/false (send mail failed)
			} else alert('Sorry, unexpected error. Please try again later.');				
		}		
	});
	
	//cancel the submit button default behaviours
	return false;
});
//if submit button is clicked
$('#subscribe-button').click(function () {		
	
	//Get the data from all the fields
	var email = $('input[name=email-input]');
	var name = $('input[name=name-input]');
	var storename = $('input[name=subscriber-store]');
	var storeid = $('input[name=subscriber-store-id]');

	//Simple validation to make sure user entered something
	//If error found, add hightlight class to the text field
	if (email.val()=='') {
		document.getElementById('email-input').style.border='3px solid red';
		$('#email-input').focus();
		return false;
	}
	//organize the data properly
	var data = 'email=' + email.val()+'&name='+name.val()+'&storename='+storename.val()+'&storeid='+storeid.val();
	
	//disabled all the text fields
	//$('#sMail').attr('disabled','true');

	var filter = /^((([a-z]|[A-Z]|[0-9]|\-|_)+(\.([a-z]|[A-Z]|[0-9]|\-|_)+)*)@((((([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.))*([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
	if (!filter.test(email.val())){
		document.getElementById('email-input').style.border='3px solid red';
		$('#email-input').focus();
		return false;
	}
	$('#subscribe-button').fadeOut('fast');
	//start the ajax
	$.ajax({
		//this is the php file that processes the data and send mail
		url: "/subscribeEmail",	
		
		//GET method is used
		type: "GET",

		//pass the data			
		data: data,		
		
		//Do not cache the page
		cache: false,
		
		//success
		success: function (html) {		
			//if process.php returned 1/true (send mail success)
			if (html=='') {					
				$('#name-input').val('');
				$('#email-input').val('');
				
				//show the success message
				$('#subscribe-button1').fadeIn('slow');
				
			//if process.php returned 0/false (send mail failed)
			} else alert('Sorry, unexpected error. Please try again later.');				
		}		
	});
	
	//cancel the submit button default behaviours
	return false;
});
function getCookie(c) {
	var b = document.cookie;
	var e = c + "=";
	var d = b.indexOf("; " + e);
	if (d == -1) {
		d = b.indexOf(e);
		if (d != 0) {
			return null
		}
	} else {
		d += 2;
		var a = document.cookie.indexOf(";", d);
		if (a == -1) {
			a = b.length
		}
	}
	return unescape(b.substring(d + e.length, a))
}